﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace HSKCards
{
    public partial class Related : Form
    {
        public SqlCeCommand comm;
        public SqlCeDataReader result;
        int ID;
        string traditional;
        string simplified;
        string pinyin;
        string english;
        string pos;
        int level;
        bool studylist;
        bool known;
        bool amend;
        public Related(char c, SqlCeConnection conn, bool trad)
        {

            InitializeComponent();

            // get entry from Database
            textBox1.Font = new Font("PMingLiUCustom", 16, FontStyle.Regular);

            comm = new System.Data.SqlServerCe.SqlCeCommand();
            comm.Connection = conn;
            comm.CommandText = "Select * from entries where ";
            if (trad) comm.CommandText+= "traditional";
            else comm.CommandText += "simplified";
            comm.CommandText+= " like '%" + c.ToString() + "%'";
            result = comm.ExecuteReader();
            while (result.Read())
            {
                ID = result.GetInt32(0);
                traditional = result.GetString(1);
                simplified = result.GetString(2);
                pinyin = result.GetString(3);
                english = result.GetString(4);
                pos = result.GetString(5);
                level = result.GetInt32(6);
                studylist = result.GetBoolean(7);
                known = result.GetBoolean(8);
                amend = result.GetBoolean(9);

                if (trad) textBox1.Text += traditional;
                else textBox1.Text += simplified;
                textBox1.Text += ", " + pinyin + ", " + english + "\r\n";
            }

            result.Close();
            comm.Dispose();
        }

        
    }
}